if(typeof xlv == 'undefined'){	
	var xlv_css_loader=function(path) {
		document.write("<link rel='stylesheet' href='/xlive/"+path+"' type='text/css'>");
	},
	xlv_js_loader=function(path) {
		document.write("<scr"+"ipt type='text/javascript' src='/xlive/"+path+"'></scr"+"ipt>");
	},
	xlv = {
		version: "0.1",
		license: "probe",
		d: {
		    env:{},
			imp:{},
			obj:{}
		},
		initialize:{},
		sessionControl:true,
		keepLive:null,
		channel:null,
		timeout:{
			lastTime:null,
			handler:null,
			interval:120000
		},
		google:{
			_$fArray:[],
			jsApiLoaded:false,
			_setjsapi:false,
			_jsApiCallback:function(){
				xlv.google.jsApiLoaded=true;
				for(var i=0,n=xlv.google._$fArray.length;i<n;++i)xlv.google._$fArray[i]();
				xlv.google._$fArray=[];
			},
			jsApi:function(func){
				if(xlv.google.jsApiLoaded){
					if(func)setTimeout(function(){func();},2);
				}else {
					if(func)xlv.google._$fArray.push(func);
					if(!xlv.google._setjspai){
						var key='';
						var script = document.createElement('script');
						script.src = 'http://www.google.com/jsapi?key='+key+'&callback=xlv.google._jsApiCallback';
						script.type = 'text/javascript';
						document.getElementsByTagName('head')[0].appendChild(script);
						xlv.google._setjspai=true;
					}
				}
			}
		},
		dispose:{},
		imp:{},
		obj:{},
		sys:{},
		object:{},
		util:{}
};
	xlv.initialize = function(){
		if(this._extended) return;
		this._extended = true;
		xlv.makeEnvironment();
    	if(window.removeEventListener) window.removeEventListener('load', xlv.initialize, false);
    	else if(window.detachEvent) window.detachEvent('onload', xlv.initialize);
    	if(window.addEventListener) window.addEventListener('unload', xlv.dispose, false);
    	else if(window.attachEvent) window.attachEvent('onunload', xlv.dispose);
    	xlv.timeout.lastTime=new Date().getTime();
    	xlv.timeout.handler=setInterval(function(){xlv.keepLive();}, xlv.timeout.interval);
	};
	xlv.keepLive=function(){
		if((new Date().getTime())-xlv.timeout.lastTime>xlv.timeout.interval){
			if(xlv.sys.xSessionId){
				var url='/xlive/web/user?method=keep-live';
				var options={
						postBody:'',
					    evalJSON:false,
					    evalJS:false,
					    requestHeaders:{
							'X-XLive-Version':xlv.version,
							'X-XLive-Content':'xml',
							'xsessionid':xlv.sys.xSessionId
						}
					};
				options.onException=function(){
					clearInterval(xlv.timeout.handler);
				};
				options.onComplete=function(aT,aJ){
					var xid=aT.transport.getResponseHeader('xsessionid');
					var shutdown=xlv.sessionControl&&(xid!=xlv.sys.xSessionId);
					if(!aT.responseXML||shutdown){
						clearInterval(xlv.timeout.handler);
						if(xlv.channel){
							xlv.channle=null;
							xlv.channel.$V.dead=true;
							xlv.channel.closeChannel();
						}
						alert('session lost or xlive web shutdown');
						if(xlv.desktop) xlv.sys.dispose(xlv.desktop,true);
				    	if(window.removeEventListener) window.removeEventListener('unload', xlv.dispose, false);
				    	else if(window.detachEvent) window.detachEvent('onunload', xlv.dispose);
					}
				};
				var ajax=new Ajax.Request(url,options);
			}
		}
	},
	xlv.dispose=function(){
		if(xlv.channel){
			xlv.channle=null;
			xlv.channel.$V.dead=true;
			xlv.channel.closeChannel();
		}
		if(xlv.desktop) xlv.sys.dispose(xlv.desktop,true);
    	if(window.removeEventListener) window.removeEventListener('unload', xlv.dispose, false);
    	else if(window.detachEvent) window.detachEvent('onunload', xlv.dispose);
		if(xlv.sys.xSessionId){
			var url='/xlive/web/disconnect';
			var options={
					postBody:null,
				    evalJSON:false,
				    evalJS:false,
				    requestHeaders:{
						'X-XLive-Version':xlv.version,
						'X-XLive-Content':'xml',
						'xsessionid':xlv.sys.xSessionId
					},
					onComplete:function(aT,aJ){
						xlv.sys.xSessionId = null;
					}
				};
			try{
				var ajax=new Ajax.Request(url,options);
			}catch(e){alert('disconnect error :'+e);}
		}
	};
	xlv.makeEnvironment=function(){
		var splash=document.getElementById('xlvid_splash');
		if(splash) splash.parentNode.removeChild(splash);
		xlv.desktop=document.body;
		if(!xlv.sys.xSessionId){
			var url='/xlive/web/session_control';
			var options={
				postBody:null,
			    evalJSON:false,
			    evalJS:false,
			    requestHeaders:{
					'X-XLive-Version':xlv.version,
					'X-XLive-Content':'xml',
					'xsessionid':xlv.sys.xSessionId
				}
			};
			options.onComplete=function(aT,aJ){
				xlv.sys.xSessionId=aT.transport.getResponseHeader('xsessionid');
				document.body.setAttribute('xlvobject','xlv.obj.desktop');
				xlv.sys.shell(xlv.desktop);
			};
			try{
				new Ajax.Request(url,options);
			}catch(e){alert('session control error :'+e);}
		}
	};
	xlv.splash=function(){
		var img='<img id="xlvid_splash" src="/xlive/images/_waiting.gif" style="position:absolute;left:50%;top:40%;z-Index:1000"/>';
		document.write(img);
	};
	xlv.splash();
	/////
	xlv_css_loader('css/xlvall.css');
	xlv_js_loader('script/prototype.js');
	xlv_js_loader('script/md5.js');
	xlv_js_loader('script/json2xml.js');
	xlv_js_loader('script/xml2json.js');
	xlv_js_loader('script/iscroll-min.js');
	
	xlv_js_loader('script/xlvall.js');
    if(window.addEventListener) window.addEventListener('load', xlv.initialize, false);
    else if(window.attachEvent) window.attachEvent('onload', xlv.initialize);
	
}	